package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.dto.role.RoleDTO;
import com.qk.entity.Role;
import com.qk.management.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/roles")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除角色信息：{}",id);
        roleService.delete(id);
        return Result.success();
    }
    @PutMapping
    public Result update(@RequestBody Role role){
        log.info("修改角色信息：{}",role);
        roleService.update(role);
        return Result.success();

    }

    @PostMapping()
    public Result add(@RequestBody Role role){
        log.info("添加角色信息：{}",role);
        roleService.add(role);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id){
        log.info("查询角色信息：{}",id);
        Role role = roleService.selectById(id);
        return Result.success(role);
    }
    @GetMapping
    public Result list(RoleDTO roleDTO){
        log.info("查询角色列表：{}",roleDTO);
        return roleService.list(roleDTO);
    }
    @GetMapping("/list")
    public Result selectAll(){
        log.info("查询所有角色");
        List<Role> roles =roleService.selectAll();
        return Result.success(roles);
    }

}
